package net.tp.struct.bst;

public class BinarySearch {


    public static int findPredecessor(int[] a, int from, int to, int value) {
        if (value <= a[from]) return from - 1;
        if (value > a[to-1]) return to-1;
        while (true) {
            if (from >= to-1) return from;
            int mid = (from+to) >>> 1;
            if (a[mid] < value) from = mid;
            else to = mid;
        }
    }
}
